package com.xijia.wuyouwallet.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.alibaba.fastjson.JSONObject;
import com.xijia.wuyouwallet.MyApp;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.adapter.UpgradeAdapter;
import com.xijia.wuyouwallet.api.MyCallBack;
import com.xijia.wuyouwallet.base.BaseActivity;
import com.xijia.wuyouwallet.bean.UpGradeData;
import com.xijia.wuyouwallet.utils.MyLogger;
import com.xijia.wuyouwallet.utils.UrlConfig;
import com.xijia.wuyouwallet.utils.XUtil;
import com.xijia.wuyouwallet.widget.MyListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/11 0011.
 */

public class UpgradeNewActivity extends BaseActivity implements View.OnClickListener,UpgradeAdapter.OnUpClick{

    private LinearLayout upgrade_new_rate_ll,upgrade_new_profit_ll,upgrade_new_serve_ll;
    private MyListView upgrade_new_lv;
    private ImageView upgrade_new_back;

    private List<UpGradeData.DataBean.ListBean> list;
    private UpgradeAdapter upgradeAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upgrade_new);
        initView();
    }

    private void initView(){
        upgrade_new_back = (ImageView) findViewById(R.id.upgrade_new_back);
        upgrade_new_back.setOnClickListener(this);
        upgrade_new_rate_ll = (LinearLayout) findViewById(R.id.upgrade_new_rate_ll);
        upgrade_new_rate_ll.setOnClickListener(this);
        upgrade_new_profit_ll = (LinearLayout) findViewById(R.id.upgrade_new_profit_ll);
        upgrade_new_profit_ll.setOnClickListener(this);
        upgrade_new_serve_ll = (LinearLayout) findViewById(R.id.upgrade_new_serve_ll);
        upgrade_new_serve_ll.setOnClickListener(this);
        upgrade_new_lv = (MyListView) findViewById(R.id.upgrade_new_lv);
        list = new ArrayList<>();
        upgradeAdapter = new UpgradeAdapter(list,this,this);
        upgrade_new_lv.setAdapter(upgradeAdapter);
        upgrade_new_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            }
        });
        requestData();
    }
    private void requestData(){
        Map<String,Object> map = new HashMap<>();
        map.put("user", MyApp.userData.getData().getUser_id());
        XUtil.Post(UrlConfig.UPGRADE_LIST_URL,map,new MyCallBack<String>(){

            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                MyLogger.wLog().e("获取升级会员列表result="+result);
                UpGradeData data = JSONObject.parseObject(result,UpGradeData.class);
                if (data.getCode()==200){
                    for (UpGradeData.DataBean.ListBean listBean : data.getData().getList()){
                        list.add(listBean);
                    }
                    upgradeAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                MyLogger.wLog().e("获取升级会员列表onError="+ex.toString());
            }
        });
    }
    @Override
    public void onClick(View view) {
        Bundle bundle = null;
        switch (view.getId()){
            case R.id.upgrade_new_back:
                finish();
                break;
            case R.id.upgrade_new_rate_ll://费率
                bundle = new Bundle();
                bundle.putString("url", UrlConfig.SETTLE_RATE_URL);
                bundle.putString("title","结算费率");
                jumpToPage(CommonWvActivity.class,bundle);
                break;
            case R.id.upgrade_new_profit_ll://盈利模式
                bundle = new Bundle();
                bundle.putString("url", UrlConfig.PROFIT_URL);
                bundle.putString("title","盈利模式");
                jumpToPage(CommonWvActivity.class,bundle);
                break;
            case R.id.upgrade_new_serve_ll://联系客服
                jumpToPage(ServeActivity.class);
                break;
        }
    }

    @Override
    public void click(int postion) {
        Bundle bundle = new Bundle();
        bundle.putString("title",list.get(postion).getMember_name());
        bundle.putString("money",list.get(postion).getMember_up_money());
        bundle.putString("id",list.get(postion).getMember_id());
        bundle.putString("name",list.get(postion).getMember_name());
        jumpToPage(UpgradeSecondActivity.class,bundle,true);
    }
}
